package cc.shacocloud.kotlin.tools.amqp

import com.rabbitmq.client.Connection

/**
 *
 * @author 思追(shaco)
 */
class AmqpTemplate(

    /**
     * 链接
     */
    private val connection: Connection

) {

    /**
     * 发送消息
     */
    fun send(exchange: String, routingKey: String, mandatory: Boolean = false, message: Message) {
        val basicProperties = message.toBasicProperties()
        connection.createChannel().use { channel ->
            channel.basicPublish(exchange, routingKey, mandatory, basicProperties, message.body)
        }
    }

}